<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>系统管理</title>
</head>
	<link href="${ctxPath}/static/theme/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath}/static/theme/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <!-- jqgrid-->
    <link href="${ctxPath}/static/theme/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">

    <link href="${ctxPath}/static/theme/css/animate.css" rel="stylesheet">
    <link href="${ctxPath}/static/theme/css/style.css?v=4.1.0" rel="stylesheet">

<body class="gray-bg">
    <div class="wrapper wrapper-content">
		<div class="row">
		<div class="ibox float-e-margins">
                    <div class="ibox-title">
                       <div class="row">
                        <form class="form-horizontal" role="form" action="#">
                            <div class="row">
                                <div class="form-group col-sm-4">
                                    <label  class="col-sm-4 control-label">名称:</label>
                                    <div class="col-sm-8">
                                        <input type="text" role="search" class="form-control input-sm" name="name" id="name">
                                    </div>
                                </div>
                                <div class="form-group col-sm-4">
                                    <label  class="col-sm-4 control-label">登录名:</label>
                                    <div class="col-sm-8">
                                        <input type="text" role="search" class="form-control input-sm" id="address" name="address">
                                    </div>
                                </div>
                                <div class="form-group col-sm-4">
                                    <label  class="col-sm-4 control-label">创建人:</label>
                                    <div class="col-sm-8">
                                        <input type="text" role="search" class="form-control input-sm" id="contact" name="contact">
                                    </div>
                                </div>
                            </div>
                            <div class="row text-center">
                                <button type="button" class="btn btn-primary" id="search_user" onclick="search()">查询</button>&nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="button" class="btn btn-primary" onclick="eliData()">清空</button>&nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="button" class="btn btn-primary" onclick="addUser()">新增</button>&nbsp;&nbsp;&nbsp;&nbsp;
                            </div>
                        </form>
                    </div>
                    </div>
                    <div class="ibox-content" id="grid_content">
                        <table id="table_data_list"></table>
						<div id="paper_list"></div>
                    </div>
                </div>
		</div>
	</div>
</body>
<script src="${ctxPath}/static/theme/js/jquery.min.js"></script>
<script src="${ctxPath}/static/theme/js/bootstrap.min.js"></script>
<!--jqgrid js-->
<script src="${ctxPath}/static/theme/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="${ctxPath}/static/theme/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>
<script>
$(function(){
	 $.jgrid.defaults.styleUI = 'Bootstrap';
     $('#table_data_list').jqGrid({
         datatype : 'json',
         url : "${ctxPath}/project/manageProject",
         mtype : 'POST',
         colNames: ["编号","名称","地址","状态","操作"],
         colModel: [
             {name: "id", index: "id", hidden:true},
             {name: "name", title: "name", width: 80},
             {name: "address", index: "address", width: 60},
             {name: "status", index: "status", width: 60,formatter:function (value, grid, rows, state) {
                 	if(value == "1"){
                     	return "正常";
                     }else if(value == "0"){
						return "未使用中心管理";
                     }
                 }
             },
             {name: "operation", index: "operation", width: 60,formatter:function (value, grid, rowObject, state) {
					return '<a title="修改信息" class="btn btn-primary btn-xs" onclick="edit(\''+rowObject.id+'\')"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;'+
					 '<a title="修改状态" onclick="changeStatus(\''+rowObject.id+'\',\''+rowObject.status+'\')" class="btn btn-primary btn-xs"><i class="fa fa-stop"></i></a>&nbsp;&nbsp;'+
					 '<a title="删除" onclick="del(\''+rowObject.id+'\')" class="btn btn-primary btn-xs"><i class="fa fa-remove"></i></a>';
                 }
             },
         ],
         height: 'auto',
         pager: "#paper_list",
         rowNum: 10,
         rowList: [10, 20, 30],
         multiselect: true,
         shrinkToFit: true,
         viewrecords : true,
         autowidth: true,
         viewrecords: true,
     }).navGrid('#paper_list',{del:false,edit:false,search:false,add:false}, {id:'myedit'});
     
     // 表格宽度调整
     function jqgridResize(width) {
         $('#table_data_list').setGridWidth(width);
     }
     // 表格宽度初始化
     jqgridResize($('#grid_content').width());
     // 表格宽度自适应
     $(window).bind('resize', function () {
         var width = $('#grid_content').width();
         jqgridResize(width);
     });

 	 // 监听事件
     $('input[role=search]').bind('keyup', function(event) {
         if (event.keyCode == "13") {
             //回车执行查询
             $('#search_user').click();
         }

     });
})


	function search() {
		var name = $('#name').val();
		var address = $('#address').val();
		var contact = $('#contact').val();
		$("#table_data_list").jqGrid('setGridParam', {
			datatype : 'json',
			page : 1
		});
		$("#table_data_list").jqGrid('setGridParam', {
			postData : {
				name : name,
				address : address,
				contact : contact,
			}
		});
		$("#table_data_list").trigger("reloadGrid");
	}

	/**
	 * 清除查询条件
	 */
	function eliData() {
		$("#contact").val("");
		$("#name").val("");
		$("#address").val("");
	}

	function addUser() {
		window.location = "${ctxPath}/project/addProject";
	}

	function edit(id) {
		window.location = "${ctxPath}/project/editInfo?project_id=" + id;
	}

	function del(id) {

		if(window.confirm('你确定要删除吗？删除后不可恢复！')){
         
         }else{
            return false;
        }
		
		if (id == null || id == '') {
			alert('删除项目出现错误！');
			return false;
		}

		$.ajax({
			type : "post",
			url : "${ctxPath}/project/delProjecct",
			data : {
				project_id : id,
			},
			dataType : "json",
			success : function(response) {
				console.log(response);
				if (response.flag) {
					$('#table_data_list').trigger("reloadGrid");
				} else {
					alert(data.msg);
				}
			}
		});
	}

	function changeStatus(id, status) {
		if (id == null || id == '') {
			alert('修改状态出现错误！');
			return false;
		}
		if (status == null || status == '') {
			alert('修改状态出现错误！');
			return false;
		}

		if (status == '1') {
			status = '0';
		} else if (status == '0') {
			status = '1';
		}

		$.ajax({
			type : "post",
			url : "${ctxPath}/project/changeStatus",
			data : {
				project_id : id,
				status : status
			},
			dataType : "json",
			success : function(response) {
				if (response.flag) {
					$('#table_data_list').trigger("reloadGrid");
				} else {

				}
			}
		});

	}
</script>
</html>